/*
 * @Description: 使用java api的Array.sort排序
 * @Version: 
 * @Author: Weixin Zhu
 * @Date: 2020-11-25 13:50:33
 * @LastEditors: Weixin Zhu
 * @LastEditTime: 2020-12-09 18:03:20
 */
package com.zwx.algorithms.basic;

import java.util.Arrays;

import com.zwx.algorithms.constant.AlgorithmsConstant;
import com.zwx.algorithms.pub.util.AlgorithmsUtils;
import com.zwx.algorithms.pub.util.LogUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.StopWatch;

public class JavaArraySort extends AbstractArraySort {
    static final Logger log = LoggerFactory.getLogger(JavaArraySort.class);

    /**
     * @description: 使用java api的Array.sort
     * @param {Integer[]}
     *                        array
     * @return {*}
     */
    public Integer[] sort(Integer[] array) {
        // List<Integer> list = Arrays.asList(array);
        // Collections.sort(list);

        // return list.toArray(array);
        Arrays.sort(array);
        return array;
    }

    public static void main(String[] args) {
        LogUtils.resetLogLevel(log, org.slf4j.event.Level.INFO);
        Integer[] originArray = null;
        Integer[] sortResult = null;
        AbstractArraySort sort = new JavaArraySort();
        StopWatch sw = DateUtil.createStopWatch();
        originArray = AlgorithmsUtils.generateRandomArray(AlgorithmsConstant.MAX_VALUE);
        sw.start();
        sortResult = sort.sort(originArray);
        sw.stop();

        AlgorithmsUtils.printSortedArray(sortResult);
        log.info("size:{},totalStep:{},cost time:{}", sortResult.length, sort.getTotalStep(), sw.getLastTaskTimeMillis());
        log.info(sw.prettyPrint());
    }
}
